import socket
from bdtime import tt
from random import randint


client_port = randint(8000, 9000)
client_addr = ('', client_port)


client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.bind(client_addr)
client.connect(('localhost', 8888))
# client.connect(('localhost', 8000))

while True:
    # msg = bytes(input("<<<"), encoding='utf-8')
    msg = f'~~~~~ from port[{client_port}]: {tt.now(1)}'
    tt.sleep(1)
    if tt.now() > 5:
        msg = '000'
    # msg = f'aaaaa'
    client.sendall(bytes(msg, encoding='utf-8'))

    data = client.recv(1024).decode('utf-8')
    # data = client.recv(1024)

    print("{}".format(data))

print('~~~ END ~~~')